﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BitBox.Framework.KBR.DAL;
using BitBox.Framework.KBR.Model;

namespace BitBox.WinForm.BackOffice
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                UserInfo usrinfo = new UserInfo();
                UserDAL usrDal = new UserDAL();

                usrinfo.USER_NAME = txtEmail.Text;
                usrinfo.USER_PASSWORD = txtPassword.Text;

                if (usrDal.SelectByAnyFilters(usrinfo).Count != 0 && usrinfo.USER_NAME != "" && usrinfo.USER_PASSWORD !="")
                {                    
                    System.Threading.Thread newForm = new System.Threading.Thread(OpenForm);
                    newForm.Start(txtEmail.Text);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Email ou Senha inválidos");
                }
            }
            catch { }
        }

        private void btnSair_Click(object sender, EventArgs e)
        {
            DialogResult result =  MessageBox.Show("Deseja mesmo sair do KBR?","Sair do KBR",MessageBoxButtons.OKCancel);

            switch (result)
            {
                case DialogResult.OK:
                    {
                        Application.Exit();
                        break;
                    }
                case DialogResult.Cancel:
                    {
                        break;
                    }
            }
        }

        private void btnUsr_Click(object sender, EventArgs e)
        {
            try
            {
                System.Threading.Thread newForm = new System.Threading.Thread(new System.Threading.ThreadStart(OpenFormUsr));
                newForm.Start();
            }
            catch { }
        }

        public static void OpenForm(object strId)
        {
            string id = strId.ToString();
            Application.Run(new frmPrincipal(id));
        }

        public static void OpenFormUsr()
        {
            Application.Run(new frmUsuario());
        }





    }
}
